<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;

class UserController extends Controller
{
    //
    public function index(Request $request){
        $auth = $request->user();
        // var_dump($auth);
        $user = User::all();
        return view('admin/user/index', ['users' => $user, 'auth' => $auth]);
    }

    public function edit($id){
        $user = User::find($id);
        return view('admin/user/edit')->with('user', $user); 
    }

    public function update(Request $request){
        $user = User::find($request->get('id'));
        $user->name = $request->get('name');
        $user->groupm = $request->get('groupm');
        if ($user->save()){
            return redirect('admin/user');
        }else{
            return redirect('admin/user')->withErrors('更新用户失败！');
        }

    }

    public function destroy($id){
        $user = User::find($id);
        if ($user->save()){
            return redirect('admin/user');
        }else{
            return redirect('admin/user')->withErrors('更新用户失败！');
        }
    }

}